import axios from 'axios'
import { message } from 'antd'
import NproGress from 'nprogress'
import 'nprogress/nprogress.css'

axios.interceptors.request.use((config) => {
    const token = sessionStorage.getItem('token')? sessionStorage.getItem('token'): ''
    config.headers.Authorization = token
    NproGress.start()
    return config
})

// 白名单
let whiteList = ["/exam/getQuestionsType", "/user/login"]

axios.interceptors.response.use((data) => {
    // 如果存在于白名单中，将会有提示信息
    let flag = whiteList.some(item => item === data.config.url)
    if (flag) {
        message.success(data.data.msg)
    }
    NproGress.done()
    return data
})

export default axios